package com.lzdongrui.backend.service.impl;

import com.lzdongrui.backend.mapper.IndexMapper;
import com.lzdongrui.backend.service.IIndexService;
import com.lzdongrui.common.core.domain.entity.SysDept;
import com.lzdongrui.common.core.domain.entity.SysUser;
import com.lzdongrui.system.domain.SysUserRole;
import com.lzdongrui.system.mapper.SysDeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

import static org.springframework.util.ObjectUtils.isEmpty;

@Service
public class IndexServiceImpl implements IIndexService {

    @Autowired
    private IndexMapper indexMapper;

    @Autowired
    private SysDeptMapper sysDeptMapper;

    @Override
    public HashMap index(SysUser user) {
        SysUserRole sysUserRole = indexMapper.selUserRole(user.getUserId(), "fdy");// 查询是否为辅导员
        SysDept sysDept = sysDeptMapper.selectDeptById(user.getDeptId());// 查询部门信息
        if (sysDept.getParentId() == 0) {//  判断是否为超管
            return adminIndex();
        } else if (!isEmpty(sysUserRole)) {// 判断是否为辅导员
            return fdyIndex(sysUserRole.getUserId(), sysDept.getCollegeId());
        } else {// 领导部分
            return leaderIndex(sysDept.getCollegeId());
        }
    }

    /**
     * 超管首页数据
     */
    public HashMap adminIndex() {
        HashMap data = new HashMap();

        data.put("stuAtSchoolNumber", indexMapper.selStuLeaveNumber(null, null, 0));// 学生在校总数
        data.put("stuLeaveNumber", indexMapper.selStuLeaveNumber(null, null, 1));// 学生离校总数
        data.put("hasReviewedNumber", indexMapper.selHasReviewedNumber(null, null));// 全院已通过请假数
        data.put("unreviewedNumber", indexMapper.selUnreviewedNumber(null, null));// 全校待审核请假数
        data.put("assessmentTodayBackNumber", indexMapper.selAssessmentTodayBackNumber(null, null));// 全校今天已销假人数
        data.put("unEliminateNumber", indexMapper.selUnEliminateNumber(null, null));// 全院未销假人数

        return data;
    }

    /**
     * 辅导员首页数据
     */
    public HashMap fdyIndex(Long userId, Long collegeId) {
        HashMap data = new HashMap();

        data.put("stuAtSchoolNumber", indexMapper.selStuLeaveNumber(userId, collegeId, 0));// 辅导员班级学生在校总数
        data.put("stuLeaveNumber", indexMapper.selStuLeaveNumber(userId, collegeId, 1));// 辅导员班级学生离校总数
        data.put("hasReviewedNumber", indexMapper.selHasReviewedNumber(userId, collegeId));// 全院已通过请假数
        data.put("unreviewedNumber", indexMapper.selUnreviewedNumber(userId, collegeId));// 辅导员待审核请假数
        data.put("assessmentTodayBackNumber", indexMapper.selAssessmentTodayBackNumber(userId, collegeId));//  辅导员班级今天已销假人数
        data.put("unEliminateNumber", indexMapper.selUnEliminateNumber(userId, collegeId));// 全院未销假人数

        return data;
    }

    /**
     * 领导首页数据
     */
    public HashMap leaderIndex(Long collegeId) {
        HashMap data = new HashMap();

        data.put("stuAtSchoolNumber", indexMapper.selStuLeaveNumber(null, collegeId, 0));// 学生在校总数
        data.put("stuLeaveNumber", indexMapper.selStuLeaveNumber(null, collegeId, 1));// 学生离校总数
        data.put("hasReviewedNumber", indexMapper.selHasReviewedNumber(null, collegeId));// 全院已通过请假数
        data.put("unreviewedNumber", indexMapper.selUnreviewedNumber(null, collegeId));// 全院待审核请假数
        data.put("assessmentTodayBackNumber", indexMapper.selAssessmentTodayBackNumber(null, collegeId));// 全院今天已销假人数
        data.put("unEliminateNumber", indexMapper.selUnEliminateNumber(null, collegeId));// 全院未销假人数


        return data;
    }
}

